/* Simple JavaScript Inheritance
 * By John Resig http://ejohn.org/
 * MIT Licensed.
 */
// Inspired by base2 and Prototype
(function(){
  var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
  // The base Class implementation (does nothing)
  this.Class = function(){};
  
  // Create a new Class that inherits from this class
  Class.extend = function(prop) {
    var _super = this.prototype;
    
    // Instantiate a base class (but only create the instance,
    // don't run the init constructor)
    initializing = true;
    var prototype = new this();
    initializing = false;
    
    // Copy the properties over onto the new prototype
    for (var name in prop) {
        // Check if we're overwriting an existing function
        prototype[name] = typeof prop[name] == "function" && 
            typeof _super[name] == "function" && fnTest.test(prop[name]) ?
            (function(name, fn){
                return function() {
                    var tmp = this._super;
                    
                    // Add a new ._super() method that is the same method
                    // but on the super-class
                    this._super = _super[name];
                    
                    // The method only need to be bound temporarily, so we
                    // remove it when we're done executing
                    var ret = fn.apply(this, arguments);        
                    this._super = tmp;
                    
                    return ret;
                };
            })(name, prop[name]) :
            prop[name];
    }
    
    // The dummy class constructor
    function Class() {
        // All construction is actually done in the init method
        if ( !initializing && this.init )
            this.init.apply(this, arguments);
    }
    
    // Populate our constructed prototype object
    Class.prototype = prototype;
    
    // Enforce the constructor to be what we expect
    Class.constructor = Class;
    
    // And make this class extendable
    Class.extend = arguments.callee;
    
    return Class;
  };
})();


if (!Function.bind) {
    Function.prototype.bind = function(scope) {
        var _function = this;
        return function() {
            return _function.apply(scope, arguments);
        }
    }
}


/*!
 * Modernizr v1.6
 * http://www.modernizr.com
 *
 * Developed by: 
 * - Faruk Ates  http://farukat.es/
 * - Paul Irish  http://paulirish.com/
 *
 * Copyright (c) 2009-2010
 * Dual-licensed under the BSD or MIT licenses.
 * http://www.modernizr.com/license/
 */

window.Modernizr = (function(window,doc,undefined){
    var docElement = doc.documentElement;
    // Remove "no-js" class from <html> element, if it exists:
    docElement.className = docElement.className.replace(/\bno-js\b/,'') + ' js';
})(this,this.document);


// Add toogleClass to Zepto,js

(function($){
    $.fn.toggleClass = function(name){
        if (this.hasClass(name)) {
            this.removeClass(name);
            return false;
        } else {
            this.addClass(name);
            return true;
        }
    }
})(Zepto);


var MobileTrapeze = Class.extend({
    is_android  : window.navigator.userAgent.match(/(Android)\s+([0-9\.]+)/),
    is_iphone   : window.navigator.userAgent.match(/(iPhone\sOS)\s([0-9_]+)/),
    is_ipad     : window.navigator.userAgent.match(/(iPad).*OS\s([0-9_]+)/),
    is_webos    : window.navigator.userAgent.match(/(webOS)\/([0-9\.]+)/),
    
    get_screen_height : function() {
        if (this.is_iphone || this.is_ipad) {
            return (window.orientation == 0 ? window.screen.height : window.screen.width);
        } else {
            return window.screen.height;
        }
    },
    
    get_screen_width : function() {
        if (this.is_iphone || this.is_ipad) {
            return (window.orientation == 0 ? window.screen.width : window.screen.height);
        } else {
            return window.screen.width;
        }
    },
    
    render_template : function(template, values) {
        for (val in values) {
            var re = new RegExp("%\\(" + val + "\\)", "g");
            template = template.replace(re, values[val]);
        }
        return template;
    },
    
    regex_class : function(class_name) {
        return new RegExp("(^|\\s)"+class_name+"(\\s|$)");
    },
    
    extend : function() {
        var target = { }, length = arguments.length;
        for (var i = 0; i < length; i++) {
            if ((options = arguments[i]) != null) {
                for (name in options) {
                    target[name] = options[name];
                }
            }
        }
        return target;
    },
    
    create_cookie : function(name, value, hours) {
        if (hours) {
            var date = new Date();
            date.setTime(date.getTime()+(hours*60*60*1000));
            var expires = "; expires="+date.toGMTString();
        } else {
            var expires = "";
        }
        document.cookie = name+"="+value+expires+"; path=/";
    },
    
    read_cookie : function(name) {
        var name_compare = name + "=",
            c_split = document.cookie.split(';'),
            c_split_length = c_split.length,
            i = 0;
        
        for(i; i < c_split_length; i++) {
            var c = c_split[i];
            
            while (c.charAt(0)==' '){ // Trim leading spaces
                c = c.substring(1,c.length);
            }
            
            if (c.indexOf(name_compare) == 0) {
                return c.substring(name_compare.length,c.length);
            }
        }
        return null;
    },
    
    init : function() {
    }
});